{extend name="common/common"/}

{block name="content"}
<form method="post" id="form-add" action="{:url('insert')}" class="am-form am-form-horizontal">
    <div class="row">
        <div class="col-md-9">
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                    商品标题
                </div>
                <div class="am-u-sm-8 am-u-md-4">
                    <input type="text" name="title" class="am-input-sm">
                </div>
                <div class="am-hide-sm-only am-u-md-6">*必填</div>
            </div>
            <div class="am-g am-margin-top-sm">
                <div class="am-u-sm-12 am-u-md-2 am-text-right admin-form-text">
                    内容描述
                </div>
                <div class="am-u-sm-12 am-u-md-10">
                    <textarea rows="10" name="summary"></textarea>
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">状态</div>
                <div class="am-u-sm-8 am-u-md-10">
                    <select data-am-selected="{btnSize: 'sm'}" name="status">
                        <option value="1" >正常</option>
                        <option value="2" >已下架</option>
                    </select>
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">分类</div>
                <div class="am-u-sm-8 am-u-md-10">
                    <select data-am-selected="{btnSize: 'sm'}" name="cid">
                        {volist name="cates" id="v"}
                        <option value="{$v['id']}" >{$v['name']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">封面图片</div>
                <div class="am-u-sm-8 am-u-md-10">
                    <textarea id="_editor" class="hidden"></textarea>

                    <div class="row" id="post-thumbnails">

                    </div>

                    <a href="javascript:void(0);" id="set-thumbnails">设置封面图片</a>
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right"></div>
                <div class="am-u-sm-8 am-u-md-10">
                    <button type="submit" class="am-btn am-btn-primary">保存</button>
                </div>
            </div>



        </div>
    </div>
</form>
{/block}

{block name="footer"}

<script type="text/javascript" charset="utf-8" src="__ROOT__/static/common/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/static/common/ueditor/ueditor.all.js"></script>
<script>
    $(function(){
        var url = "{:url( 'ueditor.local/index')}";



        // 封面图片
        var _editor = UE.getEditor('_editor', {
            serverUrl: url
        });
        _editor.ready(function () {
            _editor.hide();
            _editor.addListener('beforeInsertImage', function ( t, arg ) {
                console.log( arg );

                var cols = '';
                for ( var i = 0; i < arg.length; i++ ) {
                    cols += '<div class="col-xs-6 post-thumbnail alert">';

                    cols += '<input type="hidden" name="head_img[]" value="' + arg[i].src + '">';
                    cols += '<img src="' + arg[i].src + '" alt="" width="100%">';

                    cols += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
                    cols += '</div>';
                }
                $( "#post-thumbnails ").append( cols );
            });
        });
        $( "#set-thumbnails" ).on("click", function () {
            var insertImage = _editor.getDialog("insertimage");
            insertImage.open();
        });
    });
</script>
{/block}